package com.xiaoyu.client.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.xiaoyu.client.R;

/**
 * @author jx
 * @date 创建时间 2018/8/21
 * @Description 分享弹窗
 */
public class ShareDialog extends Dialog {

    private View mContentView;
    private Context mCotext;
    private LinearLayout viewById;

    public ShareDialog(Context context) {
        super(context, R.style.DialogStyle);
        this.mCotext = context;
        initView();
    }

    private OnBtnClickListener onClickListener;

    public void setOnBtnClickListener(OnBtnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    private void initView() {
        mContentView = LayoutInflater.from(mCotext).inflate(
                R.layout.share_dialog, null);
        setContentView(mContentView);
        viewById = mContentView.findViewById(R.id.linear_share);
        for (int i = 0; i < viewById.getChildCount(); i++) {
            final int finalI = i;

            viewById.getChildAt(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onClickListener.onBtnClick(finalI);
                }
            });
        }

        final Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.BottomPopAnimation);//设置动画效果（这里实现从下往上慢慢出现的动画效果）
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        mContentView.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    public interface OnBtnClickListener {
        void onBtnClick(int i);
    }
}
